home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11816 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: nntp.flash.net!usenet
  2. From: Quadra-Tech <quadra@flash.net>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Converting Strings to Upper Case
  5. Date: Tue, 26 Mar 1996 11:24:41 -0600
  6. Organization: FlashNet
  7. Message-ID: <31582859.3922@flash.net>
  8. References: <4ifra6$52i@scipio.cyberstore.ca> <827087843snz@genesis.demon.co.uk>
  9. NNTP-Posting-Host: p-83.flash.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0GoldB1 (Win95; I)
  14.  
  15. Lawrence Kirby wrote:
  16. > In article <4ifra6$52i@scipio.cyberstore.ca> ejw@news.cyberstore.ca "
  17. > " writes:
  18. > >Hi,
  19. > >
  20. > >I need to write a function to convert a string containg upper or lower case
  21. > >characters to the opposite case.  Something like:
  22. > >
  23. > >  void libConvertUpperCase(char *str);  and
  24. > >  void libConvertLowerCase(char *str);
  25. > >
  26. > >and the string would be modified.  I just can't seem to wrap my head around
  27. > >the best way that I know is better than writing a for loop to check each
  28. > >element in the array?
  29. > That sentence doesn't parse. The best way that I know is to write a for loop
  30. > and check each character in the string - any method will ultimately boil
  31. > down to this. If you think you know of a better method perhaps you
  32. > could explain?
  33. > --
  34. > -----------------------------------------
  35. > Lawrence Kirby | fred@genesis.demon.co.uk
  36. > Wilts, England | 70734.126@compuserve.com
  37. > -----------------------------------------
  38.  
  39.  
  40. Try this function and see if it works for you.  Good luck.
  41.  
  42.  
  43. char string[] = "This is a String";
  44.  
  45. void char fnReverse(char letter)
  46.  
  47.  int  ndx;
  48.  
  49.   {
  50.    for (n = 0; string[n] != 0; n++)
  51.      {
  52.       if (isupper(string[n]) == 0) 
  53.         {
  54.      string[n] = tolower(string[n]);
  55.      continue;
  56.         }
  57.  
  58.       string[n] = toupper(string[n]);
  59.   }  
  60.  
  61. -- 
  62.                           \|/ ____ \|/    _     _             `  _  '
  63.                  ////       @~/ ,. \~@   o' \,=./ `o          -  (_)  -
  64.                 (o -)      /_( \__/ )_\     (o o)               '   `
  65. +-----------ooO--(_)--Ooo-----\__U_/----ooO--(_)--Ooo------------------+
  66. ^                                                                      ^
  67. ^  QUADRA-TECH BOYS                                                    ^
  68. ^  DATA PROCESSING GURU                                                ^
  69. ^  DIRECT MAIL SOFTWARE BEST OF THE BEST                               ^
  70. ^                                                                      ^
  71. +----------------------------------------------------------------------+
  72.